import java.util.Timer;
import java.util.TimerTask;

public class TimerTaskDemo {
    public static void main(String[] args) throws InterruptedException {

        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                try {
                    System.out.println(Thread.currentThread().getName() + ": BEGIN");
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + ": END");
            }
        };
        Timer timer = new Timer("美得你");
        timer.schedule(timerTask, 1L, 1000);


    }
}
